package com.itheima.作业.面向接口的多态;

import java.util.Scanner;

public class demo6 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入支付方式：[WeChat,Ali,Bank]");
        String type = sc.next();
        System.out.println("请输入支付金额：");
        int money = sc.nextInt();
        // 通过工厂类中的方法，获取支付对象，并调用支付方法完成支付// =
        Payment instance = Factory.getInstance(type);


        // 【此处完成代码】
        instance.pay(money);

    }
}




// 工厂类，专门负责创建对象
// 
class Factory{
    public static Payment getInstance(String type){
        
        Payment  payment = null;
        switch (type){
            case "wx":
                payment = new  WechatPay();
                break;
            case "ali":
                 payment = new  AliPay();
                break;
            case "yh":
                 payment = new  BankPay();
                break;
        }
        return payment;
    }
}





interface Payment {
    void pay(int money);
}


class WechatPay implements Payment {
    public void pay(int money) {
        System.out.println("微信支付成功，支付金额：" + money);
    }
}
class AliPay implements Payment {
    public void pay(int money) {
        System.out.println("支付宝支付成功，支付金额：" + money);
    }
}
class BankPay implements Payment {
    public void pay(int money) {
        System.out.println("银行卡支付成功，支付金额：" + money);
    }
}